<?php
	namespace Home\Model;
	use  Think\Model;

	class GoodsModel extends Model{

		public function getHotgoods($hot=''){
			if($hot==1){
				$list=$this->field('g.id gid,g.name  gname, g.price gp, g.stok gk,gi.name giname,c.name cname')->table('goods g,goods_img gi,category c')->where('g.id=gi.goods_id and gi.is_face=1 and g.is_hot=1 and is_bast=1 and c.id=g.cate_id')->select();
			}else{
				$list=$this->field('g.id gid,g.name  gname, g.price gp, g.stok gk,gi.name giname,c.name cname')->table('goods g,goods_img gi,category c')->where('g.id=gi.goods_id and gi.is_face=1 and g.is_hot=1 and is_bast=1 and c.id=g.cate_id')->limit(8)->select();
			}
			return $list;
		}
		public function getNewgoods($new=''){
			if($new==1){
			$list1=$this->field('g.id gid,g.name  gname, g.price gp, g.stok gk,gi.name giname,c.name cname')->table('goods g,goods_img gi,category c')->where('g.id=gi.goods_id and gi.is_face=1 and g.is_new=1 and is_bast=1 and c.id=g.cate_id')->select();
		}else{
			$list1=$this->field('g.id gid,g.name  gname, g.price gp, g.stok gk,gi.name giname,c.name cname')->table('goods g,goods_img gi,category c')->where('g.id=gi.goods_id and gi.is_face=1 and g.is_new=1 and is_bast=1 and c.id=g.cate_id')->limit(8)->select();
		}
			return $list1;
		}

		public function getGoods($id){
			
			$list=$this->field('g.id gid,g.name  gname, g.price gp, g.stok gk,gi.name giname,c.name cname')->table('goods g,goods_img gi,category c')->where("g.id=gi.goods_id and gi.is_face=1 and g.is_new=1 and is_bast=1  and g.id=".$id." and c.id=g.cate_id")->find();

			return $list;
		}


	}